vbrichclientframeworkfandomcom-20200214-history
CCairoContext
cCairoContext Contains all the functions and properties to draw elements into a cairo surface. Example 'First we need a Surface, which is a "physical thing" (a real Render-Target) Dim Srf As cCairoSurface 'a Cairo-Image-Surface is something like an allocated InMemory-Bitmap (a hDIB) Set Srf = Cairo.CreateSurface(200, 100, ImageSurface) 'Ok, now the drawing - to be able to do so, we need a Context first ... 'and the CC below is something like an hDC in GDI, but ... Dim CC As cCairoContext 'unlike in GDI, where we would "Select" a Bitmap into a hDC first... 'with Cairo we can create such a CC "anytime" from any Surface 'in a non-expensive Operation (this does not need larger CPU-cycles) Set CC = Srf.CreateContext 'the following two lines ensure a complete Surface-Fill CC.SetSourceColor vbWhite CC.Paint 'before our first rectangle, just a comment about Pixels and Scaling: 'Cairos Image-Surfaces are "normal Bitmaps" - and in this example we've 'created a 200x100 Pixel-Surface (with 32Bit ColorDepth) - the initial 'x/y Scaling-Factors of a new created CairoContext (our CC) are 1 ... 'and Scale 1 means, that the given Coords work "Pixelbased" (as in GDI) CC.Rectangle 10, 10, 180, 80 'Oh, and the above line has not drawn anything to the Pixel-Surface yet, 'it is only a Path-Definition ..., so if we want to Fill this Path, we 'must tell it explicitely - first (yet before the Fill-Command), a Color: CC.SetSourceColor vbYellow CC.Fill '<-only now the Pixel within our Path are filled and the Surface-Content is changed 'Ok, finally some Textoutput, otherwise it wouldn't be a Hello-World-Demo ;-) CC.SelectFont "Times New Roman", 25, vbRed CC.TextOut 25, 30, "Hello Cairo" 'and this is our final "beam-up-into-the-Windows-World" ... if we want 'the Cairo-PixelBuffers (the Surface-Contents) on our Windows-Screen, 'we have to use the GDI finally - Srf.DrawToDC is internally (stretch-)blitting 'our "Cairo-Pixels" and expects an hDC-Parameter for that Srf.DrawToDC hDC, 20, 20 Methods * Sub AppendPath(Path As cCairoPath) * Sub ARC(xc As Double, yc As Double, Radius As Double, As Double, As Double = 6,28318530717959) * Sub ArcNegative(xc As Double, yc As Double, Radius As Double, As Double, As Double = 6,28318530717959) * Sub CalcTextRowsInfo(Text As String, AvailableWidth As Single, MultiLine As Boolean, OnlyOnLineBreaks As Boolean, RowsCharCount() As Long, RowsCharOffset() As Long, RowCount As Long, MaxRowExtents As Single) * Sub ClearPath(As Boolean) * Sub Clip(As Boolean) * Sub ClipExplicit(X As Double, y As Double, Width As Double, Height As Double) * Sub ClosePath() * Sub ColorSplit(Color As Long, R As Double, G As Double, B As Double, As Double = 1, As Long, As Long, As Long) * Function CopyPath(As Boolean, As Double = 0,1) As cCairoPath * Sub CurveTo(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double, x3 As Double, y3 As Double) * Sub DeviceToUserDistance(dx As Double, dy As Double) * Sub DeviceToUserDistanceSingle(dx As Single, dy As Single) * Sub DeviceToUserPoint(X As Double, y As Double) * Sub DeviceToUserPointSingle(X As Single, y As Single) * Sub DrawLine(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double, As Boolean, As Double, As Long = -1, As Double = 1) * Sub DrawRegularPolygon(cx As Double, cy As Double, R As Double, SideCount As Long, As [[SplineInterpolationEnm]], R_Inner) * Function DrawText(X As Double, y As Double, dx As Double, dy As Double, S As String, As Boolean, As AlignmentConstants, As Long, As Long, As DTExtFlagsEnm, As Double = 1, As Boolean, As Double) As Long * Sub DrawTextCell(X As Double, y As Double, dx As Double, dy As Double, Text As String, As Boolean, As AlignmentConstants, As Double = 1, As Long = 16777215, As Double, As Long, As Double = 0,5) * Sub Ellipse(X As Double, y As Double, Width As Double, Height As Double, As Boolean) * Sub EllipticArcTo(rx As Double, ry As Double, xAxisRotDeg As Double, LargeArc As Boolean, Sweep As Boolean, X As Double, y As Double) * Sub Fill(As Boolean, As [[cCairoPattern]]) * Function GetCharsFittingExtentPtr(pS As Long, CharCount As Long, Extent As Double) As Long * Sub GetClipExtents(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double) * Sub GetCurrentPoint(X As Double, y As Double) * Sub GetCurrentPointSingle(X As Single, y As Single) * Sub GetFillExtents(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double) * Function GetFontHeight(As Double) As Double * Function GetLineCap() As cairo_line_cap_enm * Function GetLineJoin() As cairo_line_join_enm * Function GetLineWidth() As Double * Function GetMiterLimit() As Double * Sub GetPathExtents(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double) * Sub GetStrokeExtents(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double) * Function GetTextExtentPtr(PText As Long, CharCount As Long) As Double * Function GetTextExtents(Text As String, As Double = -1, As Double = -1) As Double * Function InFill(X As Double, y As Double) As Boolean * Function InStroke(X As Double, y As Double) As Boolean * Sub LineTo(X As Double, y As Double) * Sub Mask(Pattern As cCairoPattern) * Sub MaskSurface(Surface As cCairoSurface, As Double, As Double) * Sub MatrixAddTransform(Matrix As cCairoMatrix) * Function MatrixResetToIdentity() As cCairoMatrix * Sub MoveTo(X As Double, y As Double) * Sub Paint(As Double = 1, As [[cCairoPattern]]) * Sub Polygon(Points() As Double, As Boolean, As [[SplineInterpolationEnm]], As Boolean, As Boolean) * Sub PolygonPtr(DoublePtr As Long, PairsCount As Long, As Boolean, As [[SplineInterpolationEnm]], As Boolean, As Boolean) * Sub PolygonSingle(Points() As Single, As Boolean, As [[SplineInterpolationEnm]], As Boolean, As Boolean) * Sub PolygonSinglePtr(SinglePtr As Long, PairsCount As Long, As Boolean, As [[SplineInterpolationEnm]], As Boolean, As Boolean) * Function PopGroup(As Boolean, As [[cairo_extend_enm] = CAIRO_EXTEND_NONE]) As cCairoPattern * Sub PushGroup(As cairo_content_enm = CAIRO_CONTENT_COLOR_ALPHA, As Double, As Double, As Double, As Double) * Sub Rectangle(X As Double, y As Double, Width As Double, Height As Double, As Boolean) * Sub RelCurveTo(DX1 As Double, DY1 As Double, DX2 As Double, DY2 As Double, DX3 As Double, DY3 As Double) * Sub RelEllipticArcTo(rx As Double, ry As Double, xAxisRotDeg As Double, LargeArc As Boolean, Sweep As Boolean, X As Double, y As Double) * Sub RelLineTo(dx As Double, dy As Double) * Sub RelMoveTo(dx As Double, dy As Double) * Sub RenderSurfaceContent(SurfaceOrImageListKey, DstX As Double, DstY As Double, As Double, As Double, As cairo_filter_enm = CAIRO_FILTER_GOOD, As Double = 1, As Boolean) * Sub RenderSurfaceWithinCorners(SurfaceOrImageListKey, X1 As Double, Y1 As Double, X2 As Double, Y2 As Double, x3 As Double, y3 As Double, X4 As Double, Y4 As Double, As Double = 1, As Double = 2, As Double = 2,5) * Sub ResetClip() * Sub Restore() * Sub RotateDrawings(Angle As Double) * Sub RotateDrawingsDeg(Angle As Double) * Sub RoundedRect(X As Double, y As Double, Width As Double, Height As Double, Radius As Double, As Boolean, As [[CornerMaskEnm] = cmAll], As Boolean) * Sub Save() * Sub ScaleDrawings(sX As Double, sY As Double) * Sub SelectFont(Name As String, SIZE As Double, As Long, As Boolean, As Boolean, As Boolean, As Boolean) * Sub SetDashes(Offset As Double, ParamArray DashSequence() As Variant) * Sub SetLineCap(LineCap As cairo_line_cap_enm) * Sub SetLineJoin(LineJoin As cairo_line_join_enm) * Sub SetLineWidth(LineWidth As Double, As Boolean) * Sub SetMiterLimit(MiterLimit As Double) * Sub SetSourceColor(Color As Long, As Double = 1, As Double = 1) * Sub SetSourcePattern(Pattern As cCairoPattern) * Sub SetSourceRGB(R As Double, G As Double, B As Double) * Sub SetSourceRGBA(R As Double, G As Double, B As Double, As Double = 1) * Sub SetSourceSurface(Surface As cCairoSurface, As Double, As Double) * Sub Stroke(As Boolean, As [[cCairoPattern]]) * Sub TextOut(X As Double, y As Double, Text As String, As Boolean, As Double = 1, As Boolean) * Sub TextOutPtr(X As Double, y As Double, PText As Long, CharCount As Long, As Boolean, As Double = 1, As Boolean, As Boolean) * Function ToBSTR(B() As Byte, As [[MSCodePages] = CP_UTF8]) As String * Sub TranslateDrawings(tX As Double, tY As Double) * Sub TranslateOLEColor(Color As Long) * Sub UserToDeviceDistance(dx As Double, dy As Double) * Sub UserToDeviceDistanceSingle(dx As Single, dy As Single) * Sub UserToDevicePoint(X As Double, y As Double) * Sub UserToDevicePointSingle(X As Single, y As Single) Properties * Property AntiAlias As cairo_antialias_enm * Property FillRule As cairo_fill_rule_enm * Property hCR As Long read-only * Property Matrix As cCairoMatrix * Property Operator As cairo_operator_enm * Property Surface As cCairoSurface read-only * Property Tolerance As Double Category:VbRichClient5‏‎